<?php
/**
 * 
 * IndexAction.class.php (前台首页)
 *
 * @package      	YOURPHP
 * @author          liuxun QQ:147613338 <admin@yourphp.cn>
 * @copyright     	Copyright (c) 2008-2011  (http://www.yourphp.cn)
 * @license         http://www.yourphp.cn/license.txt
 * @version        	YourPHP企业网站管理系统 v2.1 2011-03-01 yourphp.cn $
 */
if(!defined("Yourphp")) exit("Access Denied");
class IndexAction extends BaseAction
{
    function _initialize()
    {	
		parent::_initialize();

    }
    //主页
    public function index()
    {
		//1550764800
        //13岗位 12项目 14专业 23电子教案表 22微课表 21任务表 24文档课件表 25素材表
        //$this->getarrbygid('22',4) id查询
        //$this->p($this->getarrbyid('14',id));exit; 列表查询
        //访问统计
        $cache_uid=0;
        if(!empty(cookie('userid')))
        {
            $cache_uid=cookie('userid');
        }
        //echo $cache_uid;
        if(empty(S('cache_common_index_zy_uid_'.$cache_uid)))
        {
            $zy=$this->getarrbyid('14','',false);
            //专业
            foreach ($zy as $key => $value) {
                $gw=$this->getarrbygid('13',$value['id']['val'],false);
                
                //岗位  
                foreach ($gw as $key2 => $value2) {
                    $xm=$this->getarrbygid('12',$value2['id']['val'],false);
                    //项目
                    
                    $gw[$key2]['xmlist']=$xm;
                    unset($xm);
                    
                    //电子教案
                
                    
                } 
                unset($key2);
                unset($value2);
        
                $zy[$key]['gwlist']=$gw;
                unset($gw);
    
            }
            unset($key);
            unset($value);
            S('cache_common_index_zy_uid_'.$cache_uid,$zy,86400);
        }
        $zy=S('cache_common_index_zy_uid_'.$cache_uid);

        if(empty(S('cache_common_index_hdp')))
        {
            $hdp=M('slide_data')->field('pic,link,title')->where(array('fid'=>'1','lang'=>'1'))->select();

            foreach ($hdp as $key => $value) {
                $hdimg=thumb($value['pic'],1920,360);
                $hdp[$key]['pic']=$hdimg;
            }
            unset($key);
            unset($value);
            S('cache_common_index_hdp',$hdp,86400);
        }
        $hdp=S('cache_common_index_hdp');
         
        if(empty(S('cache_common_index_jingpingw')))
        {
        //精品岗位推荐
            $jingpingw = M('gangwei')->where(array('recommend'=>1))->order('listorder asc ,id desc')->limit('8')->select() ;
            foreach($jingpingw as $key=>$value){
                $jingpingw[$key]['xmcount'] = M('f_item')->where(array('gwid'=>$value['id']))->count() ;
            }
            S('cache_common_index_jingpingw',$jingpingw,1000);
        }
        $jingpingw=S('cache_common_index_jingpingw');

        $this->assign('jingpingw',$jingpingw);
        //推荐新闻
        $tuijian = M('article')->field('id,thumb,title')->where("(recommend = '1' or remen = '1') and (catid = '23' or catid = '24' or catid = '25' or catid = '26' or catid = '27')  ")->limit(4)->order('listorder asc,id desc')->select();
        $this->assign('tuijian', $tuijian);

        //不推荐新闻
        $notuijian = M('article')->field('id,thumb,title,createtime')->where(" (recommend <> '1' and remen <> '1') and (catid = '23' or catid = '24' or catid = '25' or catid = '26' or catid = '27') ")->limit(10)->order('listorder asc,id desc')->select();
        $this->assign('notuijian', $notuijian);
        
         //$this->assign('menu',json_encode($njson));
         $this->assign('data',$zy);
         $this->assign('hdp',$hdp);
         
         $this->display();
    }
    //全部课程，原主页
    public function allcourse()
    {
        //13岗位 12项目 14专业 23电子教案表 22微课表 21任务表 24文档课件表 25素材表
        //$this->getarrbygid('22',4) id查询
        //$this->p($this->getarrbyid('14',id));exit; 列表查询
        //$t1 = microtime(true);  
        $cache_uid=0;
        if(!empty(cookie('userid')))
        {
            $cache_uid=cookie('userid');
        }
        //echo $cache_uid;
        S('cache_common_allcourse_zy_uid_'.$cache_uid,null) ;
        if(empty(S('cache_common_allcourse_zy_uid_'.$cache_uid)))
        {
            $zy=$this->getarrbyid('14','',false);     
            //专业
            foreach ($zy as $key => $value) {
                $gw=$this->getarrbygid('13',$value['id']['val'],false);
                $dzjcnum=0;
                $jxspnum=0;
                $wkkjnum=0;
                $dzjanum=0;
                $qtkjnum=0;
                $jxscnum=0;
                $rwsnum=0;
                //岗位  
                foreach ($gw as $key2 => $value2) { 
                    $xm=$this->getarrbygid('12',$value2['id']['val'],false);              
                    //项目
                    foreach ($xm as $key3 => $value3) {
                        $rwgw=0;
                        $wkgw=0;
                        $scgw=0;
                        $jxspnum+=$this->getjxspnum($value3['id']['val']);
                        //微课
                        $wkin=$this->getnumbygid('22',$value3['id']['val']);
                        $wkgw=$wkin;
                        $wkkjnum+=$wkin;

                        $dzjanum+=$this->getnumbygid('23',$value3['id']['val']);
                        $qtkjnum+=$this->getnumbygid('24',$value3['id']['val']);

                        //素材
                        //$scin=$this->getnumbygid('25',$value3['id']['val']);
                        $scin=$this->getscbnum($value3['id']['val']);
                        $jxscnum+=$scin;
                        $scgw=$scin;
                        //任务数量
                        $rwin=$this->getnumbygid('21',$value3['id']['val']);
                        $rwsnum+=$rwin;
                        $rwgw=$rwin;
                        $xm[$key3]['wkkjnum']['val']=$wkgw;
                        $xm[$key3]['jxscnum']['val']=$scgw;
                        $xm[$key3]['rwsnum']['val']=$rwgw;
                        $xm[$key3]['bigimage']['val']=thumb($value3['bigimage']['val'],280,160);
                    }
                    $gw[$key2]['xmlist']=$xm;
                    unset($xm);
                    unset($value3);
                    unset($key3);
                    //电子教案
                } 
                unset($key2);
                unset($value2);
                $zy[$key]['dzjcnum']['val']=$rwsnum;
                $zy[$key]['jxspnum']['val']=$jxspnum;
                $zy[$key]['wkkjnum']['val']=$wkkjnum;
                $zy[$key]['dzjanum']['val']=$dzjanum;
                $zy[$key]['qtkjnum']['val']=$qtkjnum;
                $zy[$key]['jxscnum']['val']=$jxscnum;
                $zy[$key]['rwsnum']['val']=$rwsnum;
                $zy[$key]['gwlist']=$gw;
                unset($gw);

            }
            // $t2 = microtime(true);  
            // echo  (($t2-$t1)*1000).'ms'; 
            unset($key);
            unset($value);
            S('cache_common_allcourse_zy_uid_'.$cache_uid,$zy,86400);
        }
        $zy=S('cache_common_allcourse_zy_uid_'.$cache_uid);
        
        if(empty(S('cache_common_index_hdp')))
        {
            $hdp=M('slide_data')->field('pic,link,title')->where(array('fid'=>'1','lang'=>'1'))->select();

            foreach ($hdp as $key => $value) {
                $hdimg=thumb($value['pic'],1920,360);
                $hdp[$key]['pic']=$hdimg;
            }
            unset($key);
            unset($value);
            S('cache_common_index_hdp',$hdp,86400);
        }
        $hdp=S('cache_common_index_hdp');

        $njson=array();
        foreach($zy as $key=>$value){
            foreach ($value as $key2 => $value2) {
                if($key2=='id')
                {
                    //$value2['attr']=[];
                    $njson[$key][$key2]=$value2;
                }
                if($key2=='gwlist')
                {
                    foreach ($value2 as $key3 => $value3) {
                        foreach ($value3 as $key4 => $value4) {
                            if($key4=='title'||$key4=='id')
                            {
                                //$value4['attr']=[];
                                $njson[$key][$key2][$key3][$key4]=$value4;
                            }
                            if($key4=='xmlist')
                            {
                                foreach ($value4 as $key5 => $value5) {
                                    foreach ($value5 as $key6 => $value6) {
                                        if($key6=='title'||$key6=='id'||$key6=='bigimage'||$key6=='rwsnum'||$key6=='wkkjnum'||$key6=='jxscnum'||$key6=='fileonoff')
                                        {
                                            //$value6['attr']=[];
                                            $njson[$key][$key2][$key3][$key4][$key5][$key6]=$value6;
                                        }
                                        
                                         
                                    }
                                    unset($key6);
                                    unset($value6);
                                    
                                }
                                unset($key5);
                                unset($value5);
                            }
                            else
                            {
                                $njson[$key][$key2][$key3]['xmlist']=[];
                            }
                            
                        }
                        unset($key4);
                        unset($value4);
                        
                    }
                    unset($key3);
                    unset($value3);
                }
                
            }
            unset($key2);
            unset($value2);
            
        }
        unset($key);
        unset($value);
         $this->assign('menu',json_encode($njson));
         $this->assign('data',$zy);
         $this->assign('hdp',$hdp);
          
         $this->display();
    }

   public function notice() {
        if ($_GET['pid'] == '26') {
            $cid = 27;
        } elseif ($_GET['pid'] == '27') {
            $cid = 26;
        }
        $rightblock = M('article')->where(array('catid' => $cid))->limit(5)->order('id desc')->select();
        $this->assign('rightblock', $rightblock);
        $this->assign('pid', $_GET['pid']);
        $this->display();
    }

    //获得notice新闻列表
    public function getnotice() {
        $p = empty($_POST['page'])? '1':$_POST['page'] ;
        $firstrow = 0 ;
        $listrows = 10 ;
        $now = $listrows*($p-1) ;
        $list = M('article')->where("catid = '".$_POST['catid']."' ")->limit("$now,$listrows")->order('listorder asc,id desc')->select();
        foreach ($list as $key => $value) {
            $list[$key]['createtime'] = date('Y-m-d', $value['createtime']);
        }
        echo json_encode($list);
    }

    public function footer()
    {   
        $data=M('link')->where(array('status'=>'1'))->select();
        $this->assign('footer',$data);
        $this->display();
    }

    //基础项目信息 
    public function pro_basic()
    {
        $o=$_GET['oid'];
        $xm =$this->getarrbyid('12',$o);
        $this->assign('xm',$xm);
        // $this->p($xm);
        // exit;
        $this->display();
    }
   
    //定位 
    public function pro_point()
    {
        $o=$_GET['oid'];
        $xm =$this->getarrbyid('12',$o);
        $this->assign('xm',$xm);
        // $this->p($xm);
        // exit;
        $this->display();
    }

     //学习目标 
     public function pro_purpose()
     {
         $o=$_GET['oid'];
         $xm =$this->getarrbyid('12',$o);
         $this->assign('xm',$xm);
         // $this->p($xm);
         // exit;
         $this->display();
     }
     //设计理念 
     public function pro_design()
     {
         $o=$_GET['oid'];
         $xm =$this->getarrbyid('12',$o);
         $this->assign('xm',$xm);
        //  $this->p($xm[0]['s_list']);
         // exit;
         $this->display();
     
        }
        // 教学建议（设计）
     public function pro_advice()
     {
         $o=$_GET['oid'];
         $xm =$this->getarrbyid('12',$o);
         $this->assign('xm',$xm);
          //$this->p($xm[0]['j_list']['val']);
         // exit;
         $this->display();
     
        }
        //课程考核
    public function pro_test()
    {
        $o=$_GET['oid'];
        $xm =$this->getarrbyid('12',$o);
        $this->assign('xm',$xm);
        // $this->p($xm);
        // exit;
        $this->display();
    
        }
        
    //专业资源页
    public function detailszyzy() {
              $pid = $_GET['pid'];
        $this->assign('pid', $_GET['pid']);
        $quanx = json_decode($this->http('http://user.fjhgkj.com.cn/index.php?m=Home&c=Index&a=get_username', array('id' => cookie('userid'), 'type' => cookie('groupid'))), 'true');
        $accarr = explode(',', $quanx['school_zy']);
        if (!in_array($pid, $accarr)) {
            echo "<script>alert('没有权限');window.location.href='index.php?m=Index&a=major&pid=" . $pid . "' ;</script>";
        }
        $moduleid = 14;
        if (empty(s('file_'.$pid))) {
            $info = M('zhuanye')->field('zyzy')->where(array('id' => $pid))->find();
            $abc = explode(":::", $info['zyzy']);
            foreach ($abc as $kk => $vv) {
                $strtoarr[$kk] = explode("|", $vv);
            }
            foreach ($strtoarr as $kkk => $vvv) {
                $type = '';
                $type = M('attachment')->field('filename,filepath,createtime,fileext')->where(array('filepath' => $vvv[0]))->find();
                if (!empty($type)) {
                    if ($type['fileext'] == 'jpg' or $type['fileext'] == 'png') {
                        $file['img'][] = $type;
                    } elseif ($type['fileext'] == 'mp4') {
                        $file['mp4'][] = $type;
                    } else {
                        $file['qita'][] = $type;
                    }
                }
            }
            s('file_'.$pid, $file, 3600);
        }
        $zy = $this->getarrbyid('14', $pid);
        $this->assign('zy', $zy);
        $this->assign('file', s('file_'.$pid));
        $this->display();
    }

    //详情页
     public function details() {
        $p = $_GET['pid'];
        $c = $_GET['cid'];
        $o = $_GET['oid'];
        $quanx = json_decode($this->http('http://user.fjhgkj.com.cn/index.php?m=Home&c=Index&a=get_username', array('id' => cookie('userid'), 'type' => cookie('groupid'))), 'true');
        $accarr = explode(',', $quanx['school_zy']);
        $type = 2 ;
        if (in_array($p, $accarr) && $quanx['is_download'] == 1) {
             $type = 1 ;
        }
        $this->assign('type',$type);
        //电子教材
         $o=$_GET['oid'];
         $rw=$this->getarrbygid('21',$o);
         //print_r($rw) ;
         $this->assign('rw',$rw);
        //电子教材
        //电子课件
        $kj=$this->getarrbygid('24',$o);
        $empty = "<p class='col-xs-12'>暂时没有相关数据</p>";
        
        // 判断 视频是否为空
        $rwempty = 0;
        $rwwjempty = 0;
        foreach ($rw as $vo) {
            if(sizeof($vo["rwsp"]['val'])){
                $rwempty = 1;
                break;
            };
            if(!empty($vo["rwwj"]['val'])){
                $rwwjempty = 1;
                break;
            }
        }
        $this->assign('empty',$empty);
        $this->assign('ja',$kj);
        $this->assign('rwempty',$rwempty);
        $this->assign('rwwjempty',$rwwjempty);
       
         //电子课件
         //延伸资源
                  $wk=$this->getarrbygid('22',$o);
         //其他
      $sc=$this->getarrbygid('25',$o);
        $iskey=$this->getiskey($o);
      //个人
        $as = '';
        $bo = "";
         if($this->_ms=='2'&&$iskey)
         {
             $as = $this->getresources(0,$o)[$o];
             $bo = $this->getresources(1,$o)[$o];
        }
        //空内容显示站位
         $this->assign('empty',"<p class='col-xs-12'>暂时没有相关数据</p>");
         $this->assign('oid',$o);
         $this->assign('sc',$sc);
         $this->assign('iskey',$iskey);

         $this->assign('wk',$wk);
       
        $this->assign('as',$as);
        $this->assign('bo',$bo);
         //延伸资源
        //专业
        $zy = $this->getarrbyid('14', $p);
        //岗位
        $gw = $this->getarrbyid('13', $c);
        $xm = array();
        $xmlist = $this->getarrbygid('12', $c);
        $i = 1;
        foreach ($xmlist as $key => $value) {
            $xmlist[$key]['xmid']['val'] = ($i < 10 ? $i : $i);
            if ($value['id']['val'] == $o) {
                $xm = $xmlist[$key];
            }
            $i++;
        }
        //浏览统计

        M('f_item')->where(array('id' => $_GET['oid']))->setInc('readpoint', 1);
        if ($this->_userid) {
            $ggg = M('readrecord')->where(array('userid' => $this->_userid,'groupid'=> cookie('groupid'), 'fid' => $o))->find();
            $ttt = M('readrecord')->where(array('id' => $ggg['id']))->delete();
            if($ttt){
                M('f_item')->where(array('id' => $_GET['oid']))->setDec('redu', 1);
            }
                $data['userid'] = $this->_userid;
                $data['groupid'] = cookie('groupid');
                $data['fid'] = $o;
                $data['createtime'] = time();
                $ccc = M('readrecord')->add($data);
                if ($ccc) {
                    M('f_item')->where(array('id' => $_GET['oid']))->setInc('redu', 1);
                }

        }
        //浏览统计
        $tongjgw = M('gwbrowse')->where(array('riqi' => date('Y-m-d', time()),'gwid'=>$c))->find();
        if (empty($tongjgw)) {
            M('gwbrowse')->add(array('riqi' => date('Y-m-d', time()),'gwid'=>$c));
        } else {
            M('gwbrowse')->where(array('id' => $tongjgw['id']))->setInc('num');
        }
        //岗位活跃记录
        if($this->_userid){
            $uact = M('gwactive')->where(array('uid'=>$this->_userid, 'groupid'=>cookie('groupid') ,'gwid'=>$c, 'riqi'=>date('Y-m-d',time())))->find() ;
            if(empty($uact)){
                $order['gwid'] =  $c ;
                $order['uid'] =  $this->_userid ;
                $order['groupid'] = cookie('groupid') ;
                $order['riqi'] =  date('Y-m-d',time()) ;
                $order['createtime'] =  time() ;
                M('gwactive')->add($order) ;
            }
        }
        //任务
        //  $rw=$this->getarrbygid('21',$o);
        $this->assign('zy', $zy);
        $this->assign('gw', $gw);
        $this->assign('xm', $xm);
        // $this->p($rw);
        //  $this->assign('rw',$rw);
        $this->assign('xmlist', $xmlist);
        $this->display();
    }

    //电子教材 任务
    public function details_material()
    {
       
         $o=$_GET['oid'];
        
         //任务
         $rw=$this->getarrbygid('21',$o);
         $this->assign('rw',$rw);
         $this->display();
    }
    
    //电子课件 视频
    public function details_plan(){
        $o=$_GET['oid'];
        //电子课件
        $kj=$this->getarrbygid('24',$o);
        //视频
        $rw=$this->getarrbygid('21',$o);
        $empty = "<p class='col-xs-12'>暂时没有相关数据</p>";
        
        // 判断 视频是否为空
        $rwempty = 0;
        foreach ($rw as $vo) {
            if(sizeof($vo["rwsp"]['val'])){
                $rwempty = 1;
                break;
            };
        }
        $this->assign('empty',$empty);
        $this->assign('ja',$kj);
        $this->assign('rwempty',$rwempty);
        $this->assign('rw',$rw);
        $this->display();
    }
    // 上传
    public function upload(){
        $o=$_GET['oid'];
        $type = $_GET['type'];

        $this->assign('oid',$o);
        $this->assign('type',$type);
        $this->display();
    }

     //素材  //微课列表 电子教案
     public function details_download()
     {
         $o=$_GET['oid'];
        //微课
         $wk=$this->getarrbygid('22',$o);
          //题库
         $tk=$this->getarrbygid('34',$o);
         //其他
      $sc=$this->getarrbygid('25',$o);
      $emptyimg = 0 ;
      $emptyvideo = 0 ;
      foreach ($sc as $kk => $vv) {
            foreach ($vv['scwj']['val'] as $kkk => $vvv) {
                if ($vvv['type'] == 'img') {
                    $emptyimg = 1;
                }
                if ($vvv['type'] == 'video') {
                    $emptyvideo = 1;
                }
            }
        }
        $this->assign('emptyimg',$emptyimg) ;
        $this->assign('emptyvideo',$emptyvideo) ;
        $iskey=$this->getiskey($o);
      //个人
        $as = '';
        $bo = "";
         if($this->_ms=='2'&&$iskey)
         {
             $as = $this->getresources(0,$o)[$o];
             $bo = $this->getresources(1,$o)[$o];
        }
        //空内容显示站位
         $this->assign('empty',"<p class='col-xs-12'>暂时没有相关数据</p>");
         $this->assign('oid',$o);
         $this->assign('sc',$sc);
         $this->assign('iskey',$iskey);
         $this->assign('tk',$tk);
         $this->assign('wk',$wk);
       
        $this->assign('as',$as);
        $this->assign('bo',$bo);
         $this->display();
     }
      //素材
      public function details_pdf()
      {
          $o=$_GET['oid'];
      
          //其他
          $kj=$this->getarrbygid('24',$o);
          
          $this->assign('kj',$kj);
          
          $this->display();
      }
    
     //专业
     public function major()
     {
        $pid = $_GET['pid'];
        $quanx = json_decode($this->http('http://user.fjhgkj.com.cn/index.php?m=Home&c=Index&a=get_username', array('id' => cookie('userid'), 'type' => cookie('groupid'))), 'true');
        $accarr = explode(',', $quanx['school_zy']);
        $type = 2 ;
        if (in_array($pid, $accarr) && $quanx['is_download'] == 1) {
             $type = 1 ;
        }
        $this->assign('type',$type) ;
        $o= $_GET['pid'];
        $this->assign('pid',$_GET['pid']) ;
        //专业
        $zy= $this->getarrbyid('14',$o);
        
        
        if(!$_GET['cid']){
            // 专业下
            //当前数据
            $dzjcnum=0;
            $data =  $zy;
            //子集数据
             $chirds= $this->getarrbygid('13',$o);
            foreach ($chirds as $key => $value) {
                $dzjcnum=$this->getnumbygid('12',$value['id']['val']);
                $chirds[$key]['dzjcnum']['val']=$dzjcnum;
            }
             //页面数据 type zy 专业 gw 岗位
             $state= array("type"=>"zy"); 
            
           
        }else{
            //岗位下
            $c= $_GET['cid'];
            $dzjcnum=0;
            $jxspnum=0;
            $wkkjnum=0;
            $dzjanum=0;
            $qtkjnum=0;
            $jxscnum=0;
            //当前数据
            $data= $this->getarrbyid('13',$c);
            
            //页面数据 type zy 专业 gw 岗位
            $state= array("type"=>"gw"); 
            //项目
            $chirds= $this->getarrbygid('12',$c);
            
            foreach ($chirds as $key3 => $value3) {
                $jxspnum=$this->getjxspnum($value3['id']['val']);
                $wkkjnum=$this->getnumbygid('22',$value3['id']['val']);
                $dzjcnum =$this->getnumbygid('21',$value3['id']['val']);
                $tknum =$this->getnumbygid('34',$value3['id']['val']);
                $dzjanum=$this->getnumbygid('23',$value3['id']['val']);
                $qtkjnum=$this->getnumbygid('24',$value3['id']['val']);
                $jxscnum=$this->getscbnum($value3['id']['val']);
                //$jxscnum=$this->getnumbygid('25',$value3['id']['val']);
                $chirds[$key3]['dzjcnum']['val']=$dzjcnum;
                $chirds[$key3]['jxspnum']['val']=$jxspnum;
                $chirds[$key3]['wkkjnum']['val']=$wkkjnum;
                $chirds[$key3]['dzjanum']['val']=$dzjanum;
                $chirds[$key3]['tknum']['val']=$tknum;
                $chirds[$key3]['qtkjnum']['val']=$qtkjnum;
                $chirds[$key3]['jxscnum']['val']=$jxscnum;
               
            }
             

            // $i=1;
            // foreach ($gw as $key3 => $value3) {
            //     //生成项目n字符串
            //     $gw[$key3]['xmid']['val']='项目'.$this->number2Chinese($i);
            //     $i++;
            // }
        }
 
        $this->assign('state',$state);
        $this->assign('zy',$zy);
        $this->assign('data',$data);
        $this->assign('chirds',$chirds);
        $this->display();
     } 
     //major 相关信息
     public function major_details()
    {
        $z = $_GET["zid"];
        $g = $_GET["cid"];
        $o = $_GET["oid"];
         $this->assign('gw',$g) ;
        //当前数据
        if($z){
            //专业
            $data= $this->getarrbyid('14',$z);
            $gw = $this->getarrbygid('13',$z,false);
            $gwnum = count($gw);
            $dzjcnum=0;
            $jxspnum=0;
            $wkkjnum=0;
            $dzjanum=0;
            $qtkjnum=0;
            $jxscnum=0;
            $rwsnum=0;
            foreach ($gw as $key2 => $value2) { 
                $xm=$this->getarrbygid('12',$value2['id']['val'],false);              
                //项目
                foreach ($xm as $key3 => $value3) {
                    $jxspnum+=$this->getjxspnum($value3['id']['val']);
                    $wkkjnum+=$this->getnumbygid('22',$value3['id']['val']);
                    $dzjanum+=$this->getnumbygid('23',$value3['id']['val']);
                    $qtkjnum+=$this->getnumbygid('24',$value3['id']['val']);
                    $tknum+=$this->getnumbygid('34',$value3['id']['val']);
                    $jxscnum+=$this->getscbnum($value3['id']['val']);
                    $rwsnum+=$this->getnumbygid('21',$value3['id']['val']);
                }
            }
            $this->assign('gwnum',$gwnum);//岗位数量
            $this->assign('dzjcnum',$dzjcnum);//电子教材
            $this->assign('jxspnum',$jxspnum);//教学视频
            $this->assign('wkkjnum',$wkkjnum);//微课
            $this->assign('dzjanum',$dzjanum);//电子课件
            $this->assign('qtkjnum',$qtkjnum);
            $this->assign('rwsnum',$rwsnum);
            $this->assign('tknum',$tknum);

        }else if($g){
            //岗位
            $data= $this->getarrbyid('13',$g);
        }else if($o){
            //项目
            $data= $this->getarrbyid('12',$o);
        }

        $this->assign('data',$data);
         //$this->p($data);
        $this->display();
    }

    
    
 
    // 控件
    // pdf 预览
    public function pdf()
    {
        $file=trim($_GET['file']);
        $title=urldecode(trim($_GET['title']));
        // echo $title;
        $hz=findnameorext($file,'1');
        $url='';
        if($hz=='pdf'||$hz=='doc'||$hz=='docx'||$hz=='ppt'||$hz=='pptx'||$hz=='xls'||$hz=='xlsx')
        {
       
        $name=findnameorext($file,'0');
         
            switch ($hz) {
                case 'pdf':
                    $url=$file;
                    $this->assign('url',$url);
                    $this->display();
                    break;
                
                default:
                     //$g=$name.'.'.$hz;
                    $g=$this->conpdf($file,'pdf');
                    if($g['success'])
                    {
                        $result=$g['file'];
                        $url='http://conv.fjhgkj.com.cn/Common/conv/'.$result;
                        //print_r($g);
                        //echo $url;exit;
                        $this->assign('url',$url);
                        $this->assign('title',$title);
                        $this->display();
                    }
                    else
                    {
                        //print_r($g);
                        echo '转换失败'.$g['msg'];
                    }
                    break;
            }
        }
         
    }
    // word 转 html
    public function wordtohtml()
    {
        $file=trim($_GET['file']);
        $hz=findnameorext($file,'1');
        $url='';
        $path='';
        if($hz=='doc'||$hz=='docx')
        {
            $name=findnameorext($file,'0');
            
            $g=$this->conpdf($file,'html');
            if($g['success'])
            {
                $result=$g['file'];
                $url='http://conv.fjhgkj.com.cn/Common/conv/'.$name.'/'.$result;
                $path='http://conv.fjhgkj.com.cn/Common/conv/'.$name.'/';
            }
 
            
        }
        $this->ajaxReturn(array('url'=>$url,'path'=>$path));
    }
    // 视频模块
    public function video()
    {
        $file=trim($_GET['file']);
        $name=findnameorext($file,'0');
        $hz=findnameorext($file,'1');
        $gurl='';//720
        $purl='';//480
        $burl='';//360
        //浏览器ie
        $ua = $_SERVER['HTTP_USER_AGENT'];
        $ie = preg_match("/trident/i",$ua);
        $mo = preg_match("/mobile/i",$ua);
        $defaultQuality=1;
        //echo  $file;
        if($hz=='mp4')
        {
            //$gurl=$this->qiniutime($file,'720','c29b69baeabaf58a369b338bffaba2b9c59ba2ba');//720
            // $purl=$this->qiniutime($file,'480','b598389b3ca91e88cb888dbb25aa068950bb9ebb');;
            // $burl=$this->qiniutime($file,'360','3c88fd8ac689aab96d893b89c9986cb9da9b309a');;
            $gurl=$file;
            $purl=$file;
            $burl=$file;
            //$url=$file;
        }
        else
        {
            echo '不是视频文件';
            exit;
        }
        if($mo)
        {
            $defaultQuality=2;
        }
         $this->assign('gurl',$gurl);
         $this->assign('purl',$purl);
         $this->assign('burl',$burl);
         $this->assign('ua',$ie);
         $this->assign('defaultQuality',$defaultQuality);
         
        $this->display();
    }
    //电子教材 其他课件 下载
    public function downzip()
    {
        $c=$_GET['oid'];
        $type=$_GET['type']; //1dzjc 2kejian
        $num='21';
        $name='dzjc';

        $path=array();
        switch ($type) {
            case '1':
                $num='21';
                $name='dzjc';
                break;
            case '2':
                $num='24';
                $name='kejian';
                break;
        }
        $list=$this->getarrbygid($num,$c);
        foreach ($list as $key => $value) {
            foreach ($value as $key2 => $value2) {
               
                if($key2=='rwwj'||$key2=='wswj')
                {
                    if($value2['val'])
                    {
                        $file=".".$value2['val'];
                        preg_match('/\/([^\/]+\.[a-z]+)[^\/]*$/',$file,$match); 
                        $filename = explode(".", trim($match[0],'/'));

                        array_push($path,array('file'=>$file,'oldname'=>$filename[0].'.'.$filename[1],'name'=>$list[$key]['title']['val'].'.'.$filename[1]));
                    }
                     
                }
                # code...
            }
        }
        //print_r( $path);
        if(count($path)>0)
        {
            $newname=$name.$c.'n'.count($path);//文件名不带后缀
            $zipName = "./zip/".$newname.".zip";//压缩包
            $arr=$this->zipdown($path,$zipName);
            //print_r($arr);
            
            // $newname=$name.$c.'n'.count($path);//文件名不带后缀
            // $dest='./temp/'.$newname.'/';//临时地址
            //  

            // if(!file_exists($zipName)){   
            //     $copy=$this->copyfile($path,$dest);
            //     if(count($copy)>0)
            //     {
            //         $y=$this->zipDir($dest,$zipName);
            //         if($y['result'])
            //         {
            //             //$d=$this->delDirAndFile($dest,true);
            //         }
            //     }
            // }

            $this->ajaxReturn(array('file'=>$zipName,'name'=>$newname.".zip",'msg'=>$arr['msg']));
        }
        else
        {
            $this->ajaxReturn(array('file'=>'null','name'=>'null','msg'=>$y['msg']));
        }
    }
    public function count()
    {
        $zy=$this->getarrbyid('14');
        foreach ($zy as $key => $value) {
            $gw=$this->getarrbygid('13',$value['id']['val']);
              
            foreach ($gw as $key2 => $value2) {
                $xm=$this->getarrbygid('12',$value2['id']['val']);
                $dzjcnum=0;
                $jxspnum=0;
                $wkkjnum=0;
                $dzjanum=0;
                $qtkjnum=0;
                $jxscnum=0;
                $rwsnum=0;
                $gw[$key2]['xmlist']=$xm;
                foreach ($xm as $key3 => $value3) {
                    $jxspnum+=$this->getjxspnum($value3['id']['val']);
                    $wkkjnum+=$this->getnumbygid('22',$value3['id']['val']);
                    $dzjanum+=$this->getnumbygid('23',$value3['id']['val']);
                    $qtkjnum+=$this->getnumbygid('24',$value3['id']['val']);
                    $jxscnum+=$this->getscbnum($value3['id']['val']);
                    //$jxscnum+=$this->getnumbygid('25',$value3['id']['val']);
                    $rwsnum+=$this->getnumbygid('21',$value3['id']['val']);
                    
                }
                //电子教案
                $gw[$key2]['dzjcnum']['val']=count($xm);
                $gw[$key2]['jxspnum']['val']=$jxspnum;
                $gw[$key2]['wkkjnum']['val']=$wkkjnum;
                $gw[$key2]['dzjanum']['val']=$dzjanum;
                $gw[$key2]['qtkjnum']['val']=$qtkjnum;
                $gw[$key2]['jxscnum']['val']=$jxscnum;
                $gw[$key2]['rwsnum']['val']=$rwsnum;
                 
            }
            $zy[$key]['gwlist']=$gw;
 
        }
        $this->assign('data',$zy);
        $this->display();
    }
 
    public function webupload()
    {
        $type=$_GET['type'];
        $oid=$_GET['oid'];
        $info=$this->ajax_upload();
        $data=array();
        $aid=0;
        if($info['status']=='1')
        { 
            $model = M('resources');
            //保存当前数据对象
            $data['userid'] = $_REQUEST['userid'];
            $data['filename'] = $info['name'];
            $data['filepath'] = substr($info['savepath'].strtolower($info['savename']),1);
            $data['filesize'] = $info['size']; 
            $data['fileext'] = strtolower($info['extension']); 
            $data['createtime'] = time();
            $data['uploadip'] = get_client_ip();
            $data['status']='1';
            $data['uid']=$this->_userid;
            $data['type']=$type;
            $data['oid']=$oid;
            $aid = $model->add($data); 
             
        }
        $this->ajaxReturn(array('id'=>$aid,'status'=>$info['status'],'info'=>$info['info']));
    }
    public function webdelfile()
    {
        $id=$_POST['id'];
        $model = M('resources');
         
        $info=$model->where(array('id'=>$id,'uid'=>$this->_userid))->find();
         
        if($info)
        {
            //echo unlink('..'.__ROOT__.$info['filepath']);exit;
            //echo file_exists('..'.__ROOT__.$info['filepath']);exit;
            if (unlink('.'.__ROOT__.$info['filepath']))
            {
                $result=$model->where(array('id'=>$id,'uid'=>$this->_userid))->delete();
                if($result)
                {
                    $this->ajaxReturn(array('status'=>'1','info'=>'成功'));
                }
            }
        }
        $this->ajaxReturn(array('status'=>'0','info'=>'失败'));
        


    }
    public function downfile()
    {
      
        $this->p($this->getresources(1));
        //  echo $this->number2Chinese(12);
        //$a=array(array('file'=>'./Uploads/201711/5a02f4c6f2c64.jpg','name'=>'图1.jpg'),array('file'=>'./Uploads/201711/5a02f4d607638.jpg','name'=>'图2.jpg'));
        
        
        // $c=$this->copyfile($a,'jztp');
        // $a=$this->zipDir('./temp/'.'jztp','j');
        // $d=$this->delDirAndFile('./temp/'.'jztp',true);



        // $count=0;
		// $list=M('renwu')->field('rwsp')->where(array('xmid'=>'30'))->select();
		// foreach ($list as $key => $value) {
        //     if($value['rwsp'])
        //     {
        //         $rwsp=$this->convrwsp($value['rwsp']);
        //         $count+=count($rwsp);
        //     }
		// }
		// echo $count;
        //$this->p($list);
        // $file='test';
        // $datalist=array('./Uploads/201711/5a02f4c6f2c64.jpg');
        // $filename = "./zip/".$file.".zip"; //最终生成的文件名（含路径）  
		// $result=array('file'=>"/zip/".$file.".zip",'name'=>$file.".zip",'msg'=>'成功','result'=>true); 
		// if(!file_exists($filename)){   
		// //重新生成文件   
		// 	$zip = new ZipArchive();//使用本类，linux需开启zlib，windows需取消php_zip.dll前的注释   
		// 	if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {   
		// 		$result=array('file'=>"/zip/".$file.".zip",'name'=>$file.".zip",'msg'=>'无法打开文件，或者文件创建失败','result'=>false); 
		// 		//exit('无法打开文件，或者文件创建失败');
		// 	}   
		// 	foreach( $datalist as $val){   
		// 		if(file_exists($val)){   
		// 			$zip->addFile($val, basename($val));
		// 			$zip->renameName('5a02f4c6f2c64.jpg','图1.jpg');
		// 		}   
		// 	}   
		// 	$zip->close();//关闭   
		// }   
		// if(!file_exists($filename)){   
		// 	$result=array('file'=>"/zip/".$file.".zip",'name'=>$file.".zip",'msg'=>'无法找到文件','result'=>false); 
		// 	//exit("无法找到文件"); //即使创建，仍有可能失败。。。。   
		// }  
		// print_r($result);
    }
    public function qiniucallback()
    {
        $call=$_GET['call'];
        if($call=='up')
        {
            $fid=$_POST['fid'];
            $ftype=$_POST['ftype'];
            switch ($ftype) {
                case 'rwsp':
                    M('renwu')->where(array('id'=>$fid))->save(array('qiniuv'=>1));
                    break;
                case 'scwj':
                    M('scb')->where(array('id'=>$fid))->save(array('qiniuv'=>1));
                    break;
                case 'wksp':
                    M('weike')->where(array('id'=>$fid))->save(array('qiniuv'=>1));
                    break;
            }
        }
        else
        {
            //$NotifyData = file_get_contents("php://input");
            $file = fopen("conlog.txt","a");
            fwrite($file,$NotifyData = file_get_contents("php://input")); 
            fclose($file);
        }
         
    }
    public function getqiniuurl()
    {
        echo thumb('/Uploads/201711/5a3c7fa52d977.png',1920,360);
       // $pathinfo = pathinfo('/Uploads/201711/5a02f4c6f2c64.jpg');
        // print_r($pathinfo);
		//  	$t = $pathinfo['dirname'].'/thumb_280_160_'.$pathinfo['basename'];
        //  $pathinfo = pathinfo('/Uploads/201711/5a02f4c6f2c64.jpg');
        //   $nt=explode('/',$pathinfo['dirname']);
        // echo $nnt='/'.$nt[1].'/thumb/'.$nt[2];
            
        // $name=$_GET['name'];
        // $url= $this->qiniutime('/Uploads/201711/1a03bf8d783e3.mp4','720','c29b69baeabaf58a369b338bffaba2b9c59ba2ba');//720
        // echo $url;
    }

    //获取项目排行
    public function getfitem() {
        if ($_POST['aa'] == 'liulan') {
            $list = M('f_item')->field('id,gwid,title,readpoint,redu,bigimage')->order('readpoint desc, id desc')->limit('8')->select();
        } else {
            $list = M('f_item')->field('id,gwid,title,readpoint,redu,bigimage')->order('redu desc, id desc')->limit('8')->select();
        }
        foreach($list as $kk =>$vv){
           $info = M('gangwei')->field('zyid')->where(array('id'=>$vv['gwid']))->find();
           $list[$kk]['zyid'] = $info['zyid'] ;
           $list[$kk]['bigimage']=thumb($vv['bigimage'],280,160);
        }
        echo json_encode($list) ;
        exit ;
    }
    
    //播放页面
    public function detailsplay() {
        $keshi = 2 ;
        if (!empty($_GET['rwid'])) {  //教学视频（任务视频）
            $type = 'rwid';
            $xmid = M('renwu')->where(array('id' => $_GET['rwid']))->find();
            $typeid = $_GET['rwid'];
            $xiangguan = $this->getarrbygid('21', $xmid['xmid']);
            foreach ($xiangguan as $kk => $vv) {
                if ($vv['id']['val'] == $typeid) {
                    foreach ($vv['rwsp']['val'] as $kkk => $vvv) {
                        if ($vvv['file'] == $_GET['file']) {
                            if ($vvv['fileonoff'] == 'true') {
                                $keshi = 1;
                                break;
                            } else {
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (!empty($_GET['dzjc'])) {  //电子教材（任务教材）
            $type = 'dzjc';
            $xmid = M('renwu')->where(array('id' => $_GET['dzjc']))->find();
            $typeid = $_GET['dzjc'];
            $xiangguan = $this->getarrbygid('21', $xmid['xmid']);
            foreach ($xiangguan as $kk => $vv) {
                if ($vv['id']['val'] == $typeid) {
                    if ($vv['rwwj']['val'] == $_GET['file']) {
                        if ($vv['rwwjonoff']['val'] == 'true') {
                            $keshi = 1;
                            break;
                        }else{
                            break;
                        }
                    }
                }
            }
        }
        if (!empty($_GET['wkid'])) {  //微课
            $type = 'wkid';
            $xmid = M('weike')->where(array('id' => $_GET['wkid']))->find();
            $typeid = $_GET['wkid'];
            $xiangguan = $this->getarrbygid('22', $xmid['xmid']);
            foreach ($xiangguan as $kk => $vv) {
                if ($vv['id']['val'] == $typeid) {
                    if ($vv['wksp']['val'] == $_GET['file']) {
                        if ($vv['fileonoff']['val'] == 'true') {
                            $keshi = 1;
                            break;
                        }else{
                            break;
                        }
                    }
                }
            }
        }
        if (!empty($_GET['kjid'])) {  //电子课件
            $type = 'kjid';
            $xmid = M('wdkj')->where(array('id' => $_GET['kjid']))->find();
            $typeid = $_GET['kjid'];
            $xiangguan = $this->getarrbygid('24', $xmid['xmid']);
            foreach ($xiangguan as $kk => $vv) {
                if ($vv['id']['val'] == $typeid) {
                    if ($vv['wswj']['val'] == $_GET['file']) {
                        if ($vv['fileonoff']['val'] == 'true') {
                            $keshi = 1;
                            break;
                        }else{
                           break;
                        }
                    }
                }
            }
        }
        $this->assign('keshi',$keshi) ;
        if(empty(cookie('userid'))){
            $this->assign('isuser',2) ;
        }else{
            $this->assign('isuser',1) ;
        }
        //print_r($xiangguan) ;
        $this->assign('xmid',$xmid) ;
        //岗位id
        $gangweiinfo = M('f_item')->where(array('id'=>$xmid['xmid']))->find() ;
        $this->assign('gangweiinfo',$gangweiinfo) ;
        //专业id
        $zyid = M('gangwei')->where(array('id'=>$gangweiinfo['gwid']))->find() ;
        $this->assign('zyid',$zyid) ;
        //专业名称
        $zyinfo = M('zhuanye')->where(array('id'=>$zyid['zyid']))->find() ;
        $this->assign('zyinfo',$zyinfo) ;
        $this->assign('xiangguan',$xiangguan) ;
        //岗位浏览统计
        $tongjgw = M('gwbrowse')->where(array('riqi' => date('Y-m-d', time()),'gwid'=>$zyid['id']))->find();
        if (empty($tongjgw)) {
            M('gwbrowse')->add(array('riqi' => date('Y-m-d', time()),'gwid'=>$zyid['id']));
        } else {
            M('gwbrowse')->where(array('id' => $tongjgw['id']))->setInc('num');
        }
        //岗位活跃记录
        if($this->_userid){
            $uact = M('gwactive')->where(array('uid'=>$this->_userid, 'groupid'=>cookie('groupid') ,'gwid'=>$zyid['id'], 'riqi'=>date('Y-m-d',time())))->find() ;
            if(empty($uact)){
                $order['gwid'] =  $zyid['id'] ;
                $order['uid'] =  $this->_userid ;
                $order['groupid'] = cookie('groupid') ;
                $order['riqi'] =  date('Y-m-d',time()) ;
                $order['createtime'] =  time() ;
                M('gwactive')->add($order) ;
            }
        }
        //当前用户是否收藏
        $shoucang = M('videocollect')->where(array('type' => $type, 'typeid' => $typeid, 'uid' => $this->_userid,'groupid'=>cookie('groupid'), 'src' => $_GET['file']))->find();
        if(empty($shoucang)){
            $this->assign('tt',2) ;
        }else{
            $this->assign('tt',1) ;
        }
        //收藏的总用户数
        $totalsc = M('videocollect')->where(array('type' => $type, 'typeid' => $typeid, 'src' => $_GET['file']))->count();
        $this->assign('totalsc',$totalsc) ;
        $list = M('videocomment')->where(array('type' => $type, 'typeid' => $typeid,  'src' => $_GET['file']))->order('id asc')->select();
        foreach ($list as $kk=>$vv){
            $hkhk = json_decode($this->http('http://user.fjhgkj.com.cn/index.php?m=Home&c=Index&a=get_username',array('id'=>$vv['uid'],'type'=>$vv['groupid'])) ,'true') ;
            $list[$kk]['account']['realname'] = $hkhk['name'] ;
            $list[$kk]['account']['avatar'] = $hkhk['img'] ;
            $list[$kk]['createtime'] = date('Y-m-d H:i:s',$vv['createtime']) ;
        }

        $this->assign('list', $list);
        $this->assign('type', $type);
        $this->assign('typeid', $typeid);
        $this->assign('title', urldecode($_GET['title']));
        $this->assign('file', $_GET['file']);
        $this->display();
    }
    //手机版的播放
    public function detailsplaymobile() {
        $keshi = 2 ;
        if (!empty($_GET['rwid'])) {  //教学视频（任务视频）
            $type = 'rwid';
            $xmid = M('renwu')->where(array('id'=>$_GET['rwid']))->find() ;
            $typeid = $_GET['rwid'];
            $xiangguan=$this->getarrbygid('21',$xmid['xmid']);
                 foreach ($xiangguan as $kk => $vv) {
                if ($vv['id']['val'] == $typeid) {
                    foreach ($vv['rwsp']['val'] as $kkk => $vvv) {
                        if ($vvv['file'] == $_GET['file']) {
                            if ($vvv['fileonoff'] == 'true') {
                                $keshi = 1;
                                break;
                            } else {
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (!empty($_GET['dzjc'])) {  //电子教材（任务教材）
            $type = 'dzjc';
            $xmid = M('renwu')->where(array('id'=>$_GET['dzjc']))->find() ;
            $typeid = $_GET['dzjc'];
            $xiangguan=$this->getarrbygid('21',$xmid['xmid']);
            foreach ($xiangguan as $kk => $vv) {
                if ($vv['id']['val'] == $typeid) {
                    if ($vv['rwwj']['val'] == $_GET['file']) {
                        if ($vv['rwwjonoff']['val'] == 'true') {
                            $keshi = 1;
                            break;
                        }else{
                            break;
                        }
                    }
                }
            }
        }
        if (!empty($_GET['wkid'])) {  //微课
            $type = 'wkid';
            $xmid = M('weike')->where(array('id'=>$_GET['wkid']))->find() ;
            $typeid = $_GET['wkid'];
            $xiangguan=$this->getarrbygid('22',$xmid['xmid']);
             foreach ($xiangguan as $kk => $vv) {
                if ($vv['id']['val'] == $typeid) {
                    if ($vv['wksp']['val'] == $_GET['file']) {
                        if ($vv['fileonoff']['val'] == 'true') {
                            $keshi = 1;
                            break;
                        }else{
                            break;
                        }
                    }
                }
            }
        }
        if (!empty($_GET['kjid'])) {  //电子课件
            $type = 'kjid';
            $xmid = M('wdkj')->where(array('id'=>$_GET['kjid']))->find() ;
            $typeid = $_GET['kjid'];
            $xiangguan=$this->getarrbygid('24',$xmid['xmid']);
                        foreach ($xiangguan as $kk => $vv) {
                if ($vv['id']['val'] == $typeid) {
                    if ($vv['wswj']['val'] == $_GET['file']) {
                        if ($vv['fileonoff']['val'] == 'true') {
                            $keshi = 1;
                            break;
                        }else{
                            break;
                        }
                    }
                }
            }
        }
        
        $this->assign('keshi',$keshi) ;
        if(empty(cookie('userid'))){
            $this->assign('isuser',2) ;
        }else{
            $this->assign('isuser',1) ;
        }
        
        //print_r($xiangguan) ;
        $this->assign('xmid',$xmid) ;
        //项目id
        $xminfo = M('f_item')->where(array('id'=>$xmid['xmid']))->find() ;
        $this->assign('xminfo',$xminfo) ;
        //专业id
        $zyid = M('gangwei')->where(array('id'=>$xminfo['gwid']))->find() ;
        $this->assign('zyid',$zyid) ;
        
        $this->assign('xiangguan',$xiangguan) ;
        //岗位浏览统计
        $tongjgw = M('gwbrowse')->where(array('riqi' => date('Y-m-d', time()),'gwid'=>$zyid['id']))->find();
        if (empty($tongjgw)) {
            M('gwbrowse')->add(array('riqi' => date('Y-m-d', time()),'gwid'=>$zyid['id']));
        } else {
            M('gwbrowse')->where(array('id' => $tongjgw['id']))->setInc('num');
        }
        //岗位活跃记录
        if($this->_userid){
            $uact = M('gwactive')->where(array('uid'=>$this->_userid, 'groupid'=>cookie('groupid') ,'gwid'=>$zyid['id'], 'riqi'=>date('Y-m-d',time())))->find() ;
            if(empty($uact)){
                $order['gwid'] =  $zyid['id'] ;
                $order['uid'] =  $this->_userid ;
                $order['groupid'] = cookie('groupid') ;
                $order['riqi'] =  date('Y-m-d',time()) ;
                $order['createtime'] =  time() ;
                M('gwactive')->add($order) ;
            }
        }
        //当前用户是否收藏
        $shoucang = M('videocollect')->where(array('type' => $type, 'typeid' => $typeid, 'uid' => $this->_userid, 'src' => $_GET['file']))->find();
        if(empty($shoucang)){
            $this->assign('tt',2) ;
        }else{
            $this->assign('tt',1) ;
        }
        //收藏的总用户数
        $totalsc = M('videocollect')->where(array('type' => $type, 'typeid' => $typeid, 'src' => $_GET['file']))->count();
        $this->assign('totalsc',$totalsc) ;
        $list = M('videocomment')->where(array('type' => $type, 'typeid' => $typeid,  'src' => $_GET['file']))->order('id desc')->select();
        foreach ($list as $kk=>$vv){
            $acc = M('user')->where(array('id'=>$vv['uid']))->find() ;
            $list[$kk]['account']['realname'] = cookie('realname') ;
            $list[$kk]['account']['avatar'] = cookie('avatar') ;
            $list[$kk]['createtime'] = date('Y-m-d H:i:s',$vv['createtime']) ;
        }

        $this->assign('list', $list);
        $this->assign('type', $type);
        $this->assign('typeid', $typeid);
        $this->assign('title', urldecode($_GET['title']));
        $this->assign('file', $_GET['file']);
        $this->display();
    }
    //保存评论
    public function savecontent() {
        if (!$this->_userid) {
            echo json_encode(array('code' => '0002', 'msg' => '请先登录用户'));
            exit;
        } else {
            $mingan = $this->keyWordCheck($_POST['content']);
            if ($mingan != false) {
                echo json_encode(array('code' => '0001', 'msg' => '禁止词汇：' . $mingan));
                exit;
            }
            $data['type'] = $_POST['type'];
            $data['typeid'] = $_POST['typeid'];
            $data['src'] = $_POST['src'];
            $data['content'] = $_POST['content'];
            $data['uid'] = $this->_userid;
            $data['createtime'] = time();
            $data['groupid'] = cookie('groupid');
            $cc = M('videocomment')->add($data);
            if ($cc) {
                $xx = M('videocomment')->where(array('id'=>$cc))->find() ;
                $xx['createtime'] = date('Y-m-d H:i:s',$xx['createtime']) ;
                $xx['realname'] = cookie('realname') ;
                $xx['avatar'] = cookie('avatar') ;
                echo json_encode(array('code' => '0000', 'msg' => '评论成功','ping'=>$xx));
                exit;
            } else {
                echo json_encode(array('code' => '0001', 'msg' => '评论失败'));
                exit;
            }
        }
    }
    //收藏
    public function savecollect() {
        if (!$this->_userid) {
            echo json_encode(array('code' => '0002', 'msg' => '请先登录用户'));
            exit;
        } else {
            $info = M('videocollect')->where(array('type' => $_POST['type'], 'typeid' => $_POST['typeid'], 'uid' => $this->_userid, 'src' => $_POST['src']))->find();
            if (empty($info)) {
                $data['type'] = $_POST['type'];
                $data['typeid'] = $_POST['typeid'];
                $data['title'] = $_POST['title'];
                $data['src'] = $_POST['src'];
                $data['bigimage'] = $_POST['bigimage'];
                $data['uid'] = $this->_userid;
                $data['groupid'] = cookie('groupid');
                $data['createtime'] = time();
                $cc = M('videocollect')->add($data);
                if ($cc) {
                    echo json_encode(array('code' => '0000', 'msg' => '收藏成功'));
                    exit;
                } else {
                    echo json_encode(array('code' => '0001', 'msg' => '收藏失败'));
                    exit;
                }
            }else{
                $del = M('videocollect')->where(array('id' => $info['id']))->delete();
                 if ($del) {
                    echo json_encode(array('code' => '0005', 'msg' => '取消成功'));
                    exit;
                } 
            }
        }
    }
    //统计
    public function statis() {
        $zhuanye = M('zhuanye')->field('id,title')->order('id asc')->select() ;
        $this->assign('zhuanye', $zhuanye);
        for ($i = -30; $i <= 0; $i++) {
            $riqi[] = date("Y-m-d", strtotime("+".$i." day")) ;
            $gsriqi[] = date("m-d", strtotime("+".$i." day")) ;
        }
        $data['riqi'] = json_encode($riqi) ;
        $data['gsriqi'] = json_encode($gsriqi) ;
        $order=array() ;
        $brower=array() ;
        foreach($riqi as $kk=>$vv){
            $order[] = M('actuser')->where(array('riqi'=>$vv))->count() ;
			//$order[] = rand(100,300)+rand(15,20);
            $shul = M('browstatis')->where(array('riqi'=>$vv))->getfield('num') ;
			//$shul = rand(100,300)+rand(15,20);
            $brower[] = !empty($shul) ? $shul : 0 ;
        }
        $data['huoyue'] = json_encode($order) ;
        $data['brower'] = json_encode($brower) ;
        $data['gangwei'] = M('gangwei')->where(array('status' => 1))->count();
        $data['xiangmu'] = M('f_item')->where(array('status' => 1))->count();
        $data['renwu'] = M('renwu')->where(array('status' => 1))->count();
        $data['weike'] = M('weike')->where(array('status' => 1))->count();
        $xxxx = json_decode($this->http('http://user.fjhgkj.com.cn/index.php?m=Home&c=index&a=user_num',array()),'true') ;

        $data['user'] = $xxxx['total_num'];

        $data['fangwei'] = M('browstatis')->sum('num');
        $this->assign('data', $data);
        $this->display();
    }
    //获取对应的岗位
    public function getgangwei() {
        $zid = $_POST['zid'];
        $list = M('gangwei')->field('id,title')->where(array('zyid' => $zid))->order('listorder asc')->select();
        echo json_encode($list);
    }
    //获取岗位的统计
    public function getgwdata() {
        $gwid = $_POST['gwid'];
        for ($i = -30; $i <= 0; $i++) {
            $riqi[] = date("Y-m-d", strtotime("+" . $i . " day"));
            $gsriqi[] = date("m-d", strtotime("+" . $i . " day"));
        }
        if ($gwid == 'all') {
            $zyid = $_POST['zyid'];
            $arrgwid = M('gangwei')->field('id')->where(array('zyid' => $zyid))->select();
            foreach ($arrgwid as $key => $value) {
                $rrr .= $value['id'] . ',';
            }
            $strid = trim($rrr, ',');
            foreach ($riqi as $kk => $vv) {
                $gwllslall = M('gwbrowse')->where(array('riqi' => $vv, 'gwid' => array('in', $strid)))->sum('num');
				//$gwbrower[] = rand(100,200)+rand(1,9);
                $gwbrower[] = !empty($gwllslall) ? $gwllslall : 0;
                $gwhyall = M('gwactive')->where(array('riqi' => $vv, 'gwid' => array('in', $strid)))->count();
				//$gwhyall = rand(80,100)+rand(1,9);
                $gwactive[] = !empty($gwhyall) ? $gwhyall : 0;
            }
        } else {
            foreach ($riqi as $kk => $vv) {
                $gwllsl = M('gwbrowse')->where(array('riqi' => $vv, 'gwid' => $gwid))->getfield('num');
                $gwbrower[] = !empty($gwllsl) ? $gwllsl : 0;
				//$gwbrower[] = rand(100,200)+rand(1,9);
                $gwhy = M('gwactive')->where(array('riqi' => $vv, 'gwid' => $gwid))->count();
				//$gwhy = rand(20,40)+rand(1,9);
                $gwactive[] = !empty($gwhy) ? $gwhy : 0;
            }
        }
        $data['riqi'] = $riqi;
        $data['gsriqi'] = $gsriqi;
        $data['gwbrower'] = $gwbrower;
        $data['gwactive'] = $gwactive;
        echo json_encode($data);
    }

    //排行
    public function rank() {
        $liulan = M('f_item')->order('readpoint desc')->limit('10')->select();
        foreach ($liulan as $k => $v) {
            $zyid = M('gangwei')->where(array('id' => $v['gwid']))->getField('zyid');
            $liulan[$k]['zyid'] = $zyid;
        }

        $redu = M('f_item')->order('redu desc')->limit('10')->select();
        foreach ($redu as $kk => $vv) {
            $zyidv = M('gangwei')->where(array('id' => $vv['gwid']))->getField('zyid');
            $liulan[$k]['zyid'] = $zyidv;
        }

        for ($i = -6; $i <= 0; $i++) {
            $riqi[] = date("Y-m-d", strtotime("+" . $i . " day"));
        }
        $data['riqi'] = json_encode($riqi);
        $brower = array();
        foreach ($riqi as $kk => $vv) {
            $shul = M('browstatis')->where(array('riqi' => $vv))->getfield('num');
            $brower[] = !empty($shul) ? $shul : 0;
        }
        $data['brower'] = json_encode($brower);


        $this->assign('liulan', $liulan);
        $this->assign('redu', $redu);
        $this->assign('data', $data);
        $this->display();
    }
    
    //排行
    public function news() {
        //推荐
        $tuijian = M('article')->where("(recommend = '1') and (catid = '23' or catid = '24' or catid = '25' or catid = '26' or catid = '27')")->limit(1)->order('listorder asc,id desc')->select();
        $this->assign('tuijian', $tuijian);
        //热门
         $remen = M('article')->where( "(remen = '1') and (catid = '23' or catid = '24' or catid = '25' or catid = '26' or catid = '27')")->limit(3)->order('listorder asc,id desc')->select();
        $this->assign('remen', $remen);
        //公告
        $gonggao = M('article')->where(array('catid' => 26))->limit(5)->order('listorder asc,id desc')->select();
        $this->assign('gonggao', $gonggao);
        //文件
        $wenjian = M('article')->where(array('catid' => 27))->limit(5)->order('listorder asc,id desc')->select();
        $this->assign('wenjian', $wenjian);
        $this->display();
    }
    //获得新闻列表
    public function getnews() {
        $p = empty($_POST['page'])? '1':$_POST['page'] ;
        $firstrow = 0 ;
        $listrows = 10 ;
        $now = $listrows*($p-1) ;
        $list = M('article')->where(" recommend <> '1' and remen <> '1' and catid = '".$_POST['catid']."' ")->limit("$now,$listrows")->order('listorder asc,id desc')->select();
        foreach ($list as $key => $value) {
            $list[$key]['createtime'] = date('Y-m-d', $value['createtime']);
            $abc = M('actarticle')->where(array('nid' => $value['id'], 'uid' => $this->_userid,'groupid'=> cookie('groupid')))->find(); 
            $list[$key]['yizan'] = empty($abc) ? '2' : '1' ;
        }
        echo json_encode($list);
    }

    //截取中文不出乱码
    function utf_substr($str, $len) {
        for ($i = 0; $i < $len; $i++) {
            $temp_str = substr($str, 0, 1);
            if (ord($temp_str) > 127) {
                $i++;
                if ($i < $len) {
                    $new_str[] = substr($str, 0, 3);

                    $str = substr($str, 3);
                }
            } else {
                $new_str[] = substr($str, 0, 1);
                $str = substr($str, 1);
            }
        }
        return join($new_str);
    }

    //新闻详情页
    public function newsdetails(){
       $info =  M('article')->where(array('id'=>$_GET['id']))->find() ;
        $this->assign('info', $info);
        //浏览增加
        $info =  M('article')->where(array('id'=>$_GET['id']))->setInc('hits') ;
        //公告
        $gonggao = M('article')->where(array('catid' => 26))->limit(5)->order('listorder asc,id desc')->select();
        $this->assign('gonggao', $gonggao);
        //文件
        $wenjian = M('article')->where(array('catid' => 27))->limit(5)->order('listorder asc,id desc')->select();
        $this->assign('wenjian', $wenjian);
        $this->display();
    }
    
    public function zanarticle() {
        if (!$this->_userid) {
            echo json_encode(array('code' => '0002', 'msg' => '请先登录用户'));
            exit;
        } else {
            $info = M('actarticle')->where(array('nid' => $_POST['nid'], 'uid' => $this->_userid,'groupid'=> cookie('groupid')))->find(); 
            if (empty($info)) {
                $data['nid'] = $_POST['nid'];
                $data['riqi'] = date('Y-m-d',time());
                $data['uid'] = $this->_userid;
                $data['groupid'] = cookie('groupid');
                $data['createtime'] = time();
                $cc = M('actarticle')->add($data);
                M('article')->where(array('id'=>$_POST['nid']))->setInc('zan') ;
                if ($cc) {
                    $zan = M('article')->where(array('id'=>$_POST['nid']))->getField('zan') ;
                    echo json_encode(array('code' => '0000', 'msg' => '赞成功','zan'=>$zan));
                    exit;
                } else {
                    echo json_encode(array('code' => '0001', 'msg' => '赞失败'));
                    exit;
                }
            } else {
                
                    echo json_encode(array('code' => '0005', 'msg' => '您已经赞过了'));
                    exit;
                
            }
        }
    }
//招聘页面
    public function recruit(){
        $list = M('recruit')->order('id desc')->select() ;
        $this->assign('list',$list) ;
        $this->display();
    }
    //首页获取招聘信息
    public function getindexrecruit() {
        if (!empty($_POST['zhuanye'])) {
            $list = M('recruit')->field('comefrom,companyname,salary,title,url,workplace')->where(" zhuanye = '" . $_POST['zhuanye'] . "' ")->order('listorder asc,id desc')->select();
        }
        echo json_encode($list);
    }

    //获取招聘信息
    public function getrecruit() {
        $p = empty($_POST['page']) ? '1' : $_POST['page'];
        $firstrow = 0;
        $listrows = 10;
        $now = $listrows * ($p - 1);
        if (!empty($_POST['zhuanye']) && !empty($_POST['title'])) {
            $list = M('recruit')->where("(title like '%{$_POST['title']}%' or workplace like '%{$_POST['title']}%' or companyname like '%{$_POST['title']}%') and  zhuanye = '" . $_POST['zhuanye'] . "'")->limit("$now,$listrows")->order('listorder asc,id desc')->select();
        } elseif (!empty($_POST['zhuanye'])) {
            $list = M('recruit')->where(" zhuanye = '" . $_POST['zhuanye'] . "' ")->limit("$now,$listrows")->order('listorder asc,id desc')->select();
        }
        echo json_encode($list);
    }

    //搜索页面
    public function search() {
        if (IS_POST) {
            if(empty($_POST['title'])){
                echo '<script type="application/javascript">alert("请输入内容");window.location.href="index.php?m=Index&a=search";</script>';
                exit ;
            }
            if ($_POST['searchtypepost'] == '岗位') {
                $list = M('gangwei')->where(array('title' => array('like', '%' . $_POST['title'] . '%')))->select();
                foreach ($list as $key => $value) {
                    $zhuanye = M('zhuanye')->field('id,title')->where(array('id' => $value['zyid']))->find();
                    $list[$key]['zhuanyename'] = $zhuanye['title'];
                    $list[$key]['username'] = M('user')->where(array('username'=>$value['username']))->getField('realname') ;
                    $list[$key]['totalxm'] = M('f_item')->where(array('gwid' => $value['id']))->count();
                }
            }
            if ($_POST['searchtypepost'] == '项目') {
                $list = M('f_item')->where(array('title' => array('like', '%' . $_POST['title'] . '%')))->select();
                foreach ($list as $key1 => $value1) {
                    $gangwei = M('gangwei')->field('id,zyid,title')->where(array('id' => $value1['gwid']))->find();
                    $zhuanye = M('zhuanye')->field('id,title')->where(array('id' => $gangwei['zyid']))->find();
                    $list[$key1]['zhuanyename'] = $gangwei['title'];
                    $list[$key1]['zhuanyeid'] = $zhuanye['id'];
                    $list[$key1]['username'] = M('user')->where(array('username'=>$value1['username']))->getField('realname') ;;
                    $renwu = M('renwu')->where(array('xmid' => $value1['id']))->count();
                    $scb = M('scb')->where(array('xmid' => $value1['id']))->count();
                    $wdkj = M('wdkj')->where(array('xmid' => $value1['id']))->count();
                    $weike = M('weike')->where(array('xmid' => $value1['id']))->count();
                    $list[$key1]['totalxm'] = $renwu * 3 + $scb + $wdkj + $weike;
                }
            }
            if ($_POST['searchtypepost'] == '课件') {
               $list = M('attachment')->where(" (filename like '%{$_POST['title']}%') and (fieldtype = 'rwsp' or fieldtype = 'rwwj' or fieldtype = 'wswj' or fieldtype = 'wksp' ) ")->select();
               foreach($list as $key2=>$value2){
                   if($value2['fieldtype'] == 'rwsp'){
                       $ccc = explode(',',$value2['filename']) ;
                       $list[$key2]['title'] = $ccc[0];
                       $list[$key2]['type'] = 'rwid';
                       $dddd = M('renwu')->field('id,title,xmid,username')->where(array('id'=>$value2['id']))->find() ;
                      $list[$key2]['username'] = M('user')->where(array('username'=>$dddd['username']))->getField('realname') ;
                   }
                    if($value2['fieldtype'] == 'rwwj'){
                       $dddd = M('renwu')->field('id,title,xmid,username')->where(array('id'=>$value2['id']))->find() ;
                       $list[$key2]['title'] = $dddd['title'] ;
                       $list[$key2]['type'] = 'dzjc';
                       $list[$key2]['username'] = M('user')->where(array('username'=>$dddd['username']))->getField('realname') ;
                   }
                    if($value2['fieldtype'] == 'wswj'){
                       $dddd = M('Wdkj')->field('id,title,xmid,username')->where(array('id'=>$value2['id']))->find() ;
                       $list[$key2]['title'] = $dddd['title'] ;
                       $list[$key2]['type'] = 'kjid';
                       $list[$key2]['username'] = M('user')->where(array('username'=>$dddd['username']))->getField('realname') ;
                   }
                    if($value2['fieldtype'] == 'wksp'){
                       $dddd = M('Weike')->field('id,title,xmid,username')->where(array('id'=>$value2['id']))->find() ;
                       $list[$key2]['title'] = $dddd['title'] ;
                       $list[$key2]['type'] = 'wkid';
                       $list[$key2]['username'] = M('user')->where(array('username'=>$dddd['username']))->getField('realname') ;
                   }
                   $yyy = M('f_item')->where(array('id'=>$dddd['xmid']))->field('id,gwid,title')->find() ;
                   $list[$key2]['xmxx'] = $yyy;
                   $list[$key2]['gwxx'] = M('gangwei')->where(array('id'=>$yyy['gwid']))->field('id,title,zyid')->find();
                    $renwu = M('renwu')->where(array('xmid' => $list[$key2]['xmxx']['id']))->count();
                    $scb = M('scb')->where(array('xmid' => $list[$key2]['xmxx']['id']))->count();
                    $wdkj = M('wdkj')->where(array('xmid' => $list[$key2]['xmxx']['id']))->count();
                    $weike = M('weike')->where(array('xmid' => $list[$key2]['xmxx']['id']))->count();
                    $list[$key2]['totalxm'] = $renwu * 3 + $scb + $wdkj + $weike;
                    $list[$key2]['abc'] = $this->getiskey($yyy['id']) ;
               }
            }
            
             $data = array();
                if ($_POST['searchtypepost'] == '素材') {
                $quanx = json_decode($this->http('http://user.fjhgkj.com.cn/index.php?m=Home&c=Index&a=get_username', array('id' => cookie('userid'), 'type' => cookie('groupid'))), 'true');
                $accarr = explode(',', $quanx['school_zy']);
                $list = M('attachment')->where(" (filename like '%{$_POST['title']}%') and (fieldtype = 'zyzy' or fieldtype = 'scwj'  ) ")->select();
                foreach ($list as $key3 => $value3) {
                    if ($value3['fieldtype'] == 'zyzy') {
                        $zhuy = M('zhuanye')->field('id,title')->where(array('id' => $value3['id']))->find();
                        if (empty($zhuy)) {
                            unset($list[$key3]);
                        } else {
                            if (in_array($zhuy['id'], $accarr)) {
                                $list[$key3]['isok'] = true;
                            } else {
                                $list[$key3]['isok'] = false;
                            }
                            $username = M('user')->field('username')->where(array('id'=>$value3['userid']))->find() ;
                            $list[$key3]['username'] = $username['username'] ;
                            if($value3['fileext'] == 'jpg' || $value3['fileext'] == 'png'){
                                $data['img'][] = $list[$key3] ;
                            }elseif($value3['fileext'] == 'mp4' ){
                                 $data['mp4'][] = $list[$key3] ;
                            }else{
                                $data['qita'][] = $list[$key3] ;
                            }
                        }
                    }
                    if ($value3['fieldtype'] == 'scwj') {
                        $scbdtj = M('scb')->field('id,title,xmid')->where(array('id' => $value3['id']))->find();
                        if (empty($scbdtj)) {
                            unset($list[$key3]);
                        } else {
                            $fff = M('f_item')->field('id,title,gwid')->where(array('id' => $scbdtj['xmid']))->find();
                            $gwinfo = M('gangwei')->field('id,title,zyid')->where(array('id' => $fff['gwid']))->find();
                            if (in_array($gwinfo['zyid'], $accarr)) {
                                $list[$key3]['isok'] = true;
                            } else {
                                $list[$key3]['isok'] = false;
                            }
                            $username = M('user')->field('username')->where(array('id'=>$value3['userid']))->find() ;
                            $list[$key3]['username'] = $username['username'] ;
                            if($value3['fileext'] == 'jpg' || $value3['fileext'] == 'png'){
                                $data['img'][] = $list[$key3] ;
                            }elseif($value3['fileext'] == 'mp4' ){
                                $data['mp4'][] = $list[$key3] ;
                            }else{
                                $data['qita'][] = $list[$key3] ;
                            }
                        }
                    }

                }
                $this->assign('data', $data);
              
            }
    
            $this->assign('list', $list);
            $this->assign('totalnum', count($list));
            $this->assign($_POST);
        }
        $this->display();
    }
    //全部素材
    public function allmaterial() {
        $download = 2;
        $quanx = json_decode($this->http('http://user.fjhgkj.com.cn/index.php?m=Home&c=Index&a=get_username', array('id' => cookie('userid'), 'type' => cookie('groupid'))), 'true');
        if ($quanx['is_download'] == 1) {
            $download = 1;
        }
        $zhuanyelist = M('zhuanye')->field('id,title')->select() ;
        $this->assign('download',$download) ;
        $this->assign('pid',$_GET['pid']) ;
        $this->assign('zhuanyelist', $zhuanyelist);
        $this->display();
    }
    
    public function getsucaiid($zyid){
       $gwlist = M('gangwei')->field('id,title')->where(array('zyid'=>$zyid))->select() ; 
       $gwstr = '' ;
       foreach ($gwlist as $kk=>$vv){
           $gwstr .= $vv['id'].','  ;
       }
       $gwstr = trim($gwstr,',') ;
       $fitemlist = M('f_item')->field('id,title')->where("gwid in ($gwstr)")->select() ;
       $fitemstr = '' ;
       foreach($fitemlist as $kkk=>$vvv){
           $fitemstr .= $vvv['id'].','  ;
       }
       $fitemstr = trim($fitemstr,',') ;
       $scbstr = '' ;
       $scblist = M('scb')->field('id,title')->where("xmid in ($fitemstr) ")->select() ;
       foreach($scblist as $kkkkk=>$vvvvv){
           $scbstr .=$vvvvv['id'].','  ;
       }
       $scbstr = trim($scbstr,',') ;
       return $scbstr ;
    }
    public function getsucai() {
        if ($_POST['sctype'] != '素材') {
            if ($_POST['sctype'] == '岗位') {
                $list = M('gangwei')->where(array('title' => array('like', '%' . $_POST['title'] . '%')))->select();
                foreach ($list as $key => $value) {
                    $zhuanye = M('zhuanye')->field('id,title')->where(array('id' => $value['zyid']))->find();
                    $list[$key]['zhuanyename'] = $zhuanye['title'];
                    $list[$key]['username'] = M('user')->where(array('username' => $value['username']))->getField('realname');
                    $list[$key]['totalxm'] = M('f_item')->where(array('gwid' => $value['id']))->count();
                }
            }
            if ($_POST['sctype'] == '项目') {
                $list = M('f_item')->where(array('title' => array('like', '%' . $_POST['title'] . '%')))->select();
                foreach ($list as $key1 => $value1) {
                    $gangwei = M('gangwei')->field('id,zyid,title')->where(array('id' => $value1['gwid']))->find();
                    $zhuanye = M('zhuanye')->field('id,title')->where(array('id' => $gangwei['zyid']))->find();
                    $list[$key1]['zhuanyename'] = $gangwei['title'];
                    $list[$key1]['zhuanyeid'] = $zhuanye['id'];
                    $list[$key1]['username'] = M('user')->where(array('username' => $value1['username']))->getField('realname');
                    ;
                    $renwu = M('renwu')->where(array('xmid' => $value1['id']))->count();
                    $scb = M('scb')->where(array('xmid' => $value1['id']))->count();
                    $wdkj = M('wdkj')->where(array('xmid' => $value1['id']))->count();
                    $weike = M('weike')->where(array('xmid' => $value1['id']))->count();
                    $list[$key1]['totalxm'] = $renwu * 3 + $scb + $wdkj + $weike;
                }
            }
            if ($_POST['sctype'] == '课件') {
                $list = M('attachment')->where(" (filename like '%{$_POST['title']}%') and (fieldtype = 'rwsp' or fieldtype = 'rwwj' or fieldtype = 'wswj' or fieldtype = 'wksp' ) ")->select();
                foreach ($list as $key2 => $value2) {
                    if ($value2['fieldtype'] == 'rwsp') {
                        $ccc = explode(',', $value2['filename']);
                        $list[$key2]['title'] = $ccc[0];
                        $list[$key2]['type'] = 'rwid';
                        $dddd = M('renwu')->field('id,title,xmid,username')->where(array('id' => $value2['id']))->find();
                        $list[$key2]['username'] = M('user')->where(array('username' => $dddd['username']))->getField('realname');
                    }
                    if ($value2['fieldtype'] == 'rwwj') {
                        $dddd = M('renwu')->field('id,title,xmid,username')->where(array('id' => $value2['id']))->find();
                        $list[$key2]['title'] = $dddd['title'];
                        $list[$key2]['type'] = 'dzjc';
                        $list[$key2]['username'] = M('user')->where(array('username' => $dddd['username']))->getField('realname');
                    }
                    if ($value2['fieldtype'] == 'wswj') {
                        $dddd = M('Wdkj')->field('id,title,xmid,username')->where(array('id' => $value2['id']))->find();
                        $list[$key2]['title'] = $dddd['title'];
                        $list[$key2]['type'] = 'kjid';
                        $list[$key2]['username'] = M('user')->where(array('username' => $dddd['username']))->getField('realname');
                    }
                    if ($value2['fieldtype'] == 'wksp') {
                        $dddd = M('Weike')->field('id,title,xmid,username')->where(array('id' => $value2['id']))->find();
                        $list[$key2]['title'] = $dddd['title'];
                        $list[$key2]['type'] = 'wkid';
                        $list[$key2]['username'] = M('user')->where(array('username' => $dddd['username']))->getField('realname');
                    }
                    $yyy = M('f_item')->where(array('id' => $dddd['xmid']))->field('id,gwid,title')->find();
                    $list[$key2]['xmxx'] = $yyy;
                    $list[$key2]['gwxx'] = M('gangwei')->where(array('id' => $yyy['gwid']))->field('id,title,zyid')->find();
                    $renwu = M('renwu')->where(array('xmid' => $list[$key2]['xmxx']['id']))->count();
                    $scb = M('scb')->where(array('xmid' => $list[$key2]['xmxx']['id']))->count();
                    $wdkj = M('wdkj')->where(array('xmid' => $list[$key2]['xmxx']['id']))->count();
                    $weike = M('weike')->where(array('xmid' => $list[$key2]['xmxx']['id']))->count();
                    $list[$key2]['totalxm'] = $renwu * 3 + $scb + $wdkj + $weike;
                    $list[$key2]['abc'] = $this->getiskey($yyy['id']);
                }
            }
            echo json_encode(array('gxk'=>$list)) ;
            exit ;
        } else {
            $data = array();
            // if ($_POST['searchtypepost'] == '素材') {
            $quanx = json_decode($this->http('http://user.fjhgkj.com.cn/index.php?m=Home&c=Index&a=get_username', array('id' => cookie('userid'), 'type' => cookie('groupid'))), 'true');
            $accarr = explode(',', $quanx['school_zy']);
            $p = empty($_POST['page']) ? '1' : $_POST['page'];
            $firstrow = 0;
            $listrows = 50;
            $now = $listrows * ($p - 1);
            if ($_POST['playtype'] == 'pic') {
                $playtype = 'fileext = "jpg" or fileext = "png"';
            } elseif ($_POST['playtype'] == 'video') {
                $playtype = 'fileext = "mp4"';
            } elseif ($_POST['playtype'] == 'other') {
                $playtype = 'fileext <> "mp4" and fileext <> "jpg" and fileext <> "png"';
            }
            if (empty($_POST['title']) && $_POST['zyid'] == 'all') {
                $list = M('attachment')->where(" (fieldtype = 'zyzy' or fieldtype = 'scwj') and ($playtype) ")->limit("$now,$listrows")->order('aid desc')->select();
                $length = M('attachment')->where(" (fieldtype = 'zyzy' or fieldtype = 'scwj') and ($playtype) ")->select();
                $length1 = $this->retcount($length) ;
            } elseif (empty($_POST['title']) && $_POST['zyid'] != 'all') {
                $retarrfitem = $this->getsucaiid($_POST['zyid']);
                $list = M('attachment')->where("(( fieldtype = 'zyzy' and  id = '" . $_POST['zyid'] . "') or ( fieldtype = 'scwj' and  id in ($retarrfitem) )) and ($playtype) ")->limit("$now,$listrows")->order('aid desc')->select();
                $length = M('attachment')->where("(( fieldtype = 'zyzy' and  id = '" . $_POST['zyid'] . "') or ( fieldtype = 'scwj' and  id in ($retarrfitem) )) and ($playtype) ")->select();
                $length1 = $this->retcount($length) ;
            } elseif (!empty($_POST['title']) && $_POST['zyid'] == 'all') {
                $list = M('attachment')->where(" (filename like '%{$_POST['title']}%') and (fieldtype = 'zyzy' or fieldtype = 'scwj'  ) and ($playtype)  ")->limit("$now,$listrows")->select();

                $length = M('attachment')->where(" (filename like '%{$_POST['title']}%') and (fieldtype = 'zyzy' or fieldtype = 'scwj'  ) and ($playtype)  ")->select();
                $length1 = $this->retcount($length) ;
            } elseif (!empty($_POST['title']) && $_POST['zyid'] != 'all') {
                $retarrfitem = $this->getsucaiid($_POST['zyid']);
                $list = M('attachment')->where(" (filename like '%{$_POST['title']}%') and ((( fieldtype = 'zyzy' and  id = '" . $_POST['zyid'] . "') or ( fieldtype = 'scwj' and  id in ($retarrfitem) ))) and ($playtype) ")->limit("$now,$listrows")->order('aid desc')->select();
                $length = M('attachment')->where(" (filename like '%{$_POST['title']}%') and ((( fieldtype = 'zyzy' and  id = '" . $_POST['zyid'] . "') or ( fieldtype = 'scwj' and  id in ($retarrfitem) ))) and ($playtype) ")->select();
                $length1 = $this->retcount($length) ;
            }
            foreach ($list as $key3 => $value3) {
                if ($value3['fieldtype'] == 'zyzy') {
                    $zhuy = M('zhuanye')->field('id,title')->where(" (zyzy like '%{$value3['filepath']}%') and (id = '".$value3['id']."'  )" )->find();
                    if (empty($zhuy)) {
                        unset($list[$key3]);
                    } else {
                        if ( cookie('userid') &&  in_array($zhuy['id'], $accarr)) {
                            $list[$key3]['isok'] = true;
                        } else {
                            $list[$key3]['isok'] = false;
                        }
                        $username = M('user')->field('username')->where(array('id' => $value3['userid']))->find();
                        $list[$key3]['username'] = $username['username'];
                        if ($value3['fileext'] == 'jpg' || $value3['fileext'] == 'png') {
                            $data['img'][] = $list[$key3];
                        } elseif ($value3['fileext'] == 'mp4') {
                            $data['mp4'][] = $list[$key3];
                        } else {
                            $data['qita'][] = $list[$key3];
                        }
                    }
                }
                if ($value3['fieldtype'] == 'scwj') {
                    $scbdtj = M('scb')->field('id,title,xmid')->where(" (scwj like '%{$value3['filepath']}%') and (id = '".$value3['id']."'  )" )->find();
                    if (empty($scbdtj)) {
                        unset($list[$key3]);
                    } else {
                        $fff = M('f_item')->field('id,title,gwid')->where(array('id' => $scbdtj['xmid']))->find();
                        $gwinfo = M('gangwei')->field('id,title,zyid')->where(array('id' => $fff['gwid']))->find();
                        if ( cookie('userid') &&  in_array($gwinfo['zyid'], $accarr)) {
                            $list[$key3]['isok'] = true;
                        } else {
                            $list[$key3]['isok'] = false;
                        }
                        $username = M('user')->field('username')->where(array('id' => $value3['userid']))->find();
                        $list[$key3]['username'] = $username['username'];
                        if ($value3['fileext'] == 'jpg' || $value3['fileext'] == 'png') {
                            $data['img'][] = $list[$key3];
                        } elseif ($value3['fileext'] == 'mp4') {
                            $data['mp4'][] = $list[$key3];
                        } else {
                            $data['qita'][] = $list[$key3];
                        }
                    }
                }
            }
            echo json_encode(array('total' => $length1, 'data' => $data));
        }
    }

    //返回list数量
    public function retcount($list){
           foreach ($list as $key3 => $value3) {
                if ($value3['fieldtype'] == 'zyzy') {
                    $zhuy = M('zhuanye')->field('id,title')->where(" (zyzy like '%{$value3['filepath']}%') and (id = '".$value3['id']."'  )" )->find();
                    if (empty($zhuy)) {
                        unset($list[$key3]);
                    } 
                }
                if ($value3['fieldtype'] == 'scwj') {
                    $scbdtj = M('scb')->field('id,title,xmid')->where(" (scwj like '%{$value3['filepath']}%') and (id = '".$value3['id']."'  )" )->find();
                    if (empty($scbdtj)) {
                        unset($list[$key3]);
                    }
                }
            }
            return count($list) ;
    }
    // public function aaaaarenwu()
    // {
    //     $biao='scb';
    //     $zd='scwj';
    //     $moduleid=25;
    //     $i=0;
    //     $list=M($biao)->field('id,userid,title,'.$zd)->select();
    //     $arr=array();
    //     $imagearr = explode(',', 'jpg,gif,png,jpeg,bmp,ttf,tif'); 
    //     foreach ($list as $key => $value) {
    //         if($value[$zd])
    //         {
    //             $a=$this->convrwsp($value[$zd]);
    //             foreach ($a as $key2 => $value2) {
    //                 $i++;
    //                 $a[$key2]['catid']=0;
    //                 $a[$key2]['id']=$value['id'];
    //                 $a[$key2]['moduleid']=$moduleid;
    //                 $a[$key2]['fileext']=fileext($value2['file']);
    //                 $a[$key2]['isimage'] = in_array(fileext($value2['file']),$imagearr) ? 1 : 0;
    //                 if($value2['name'])
    //                 {
    //                     $a[$key2]['filename']=$value2['name'].'.'.fileext($value2['file']);
    //                 }
    //                 else
    //                 {
    //                     $a[$key2]['filename']=$value['title'].'.'.fileext($value2['file']);
    //                 }
    //                 $a[$key2]['userid']=$value['userid'];
    //                 $a[$key2]['isthumb']=0;
    //                 $a[$key2]['createtime']=time();
    //                 $a[$key2]['uploadip']='0.0.0.0';
    //                 $a[$key2]['status']=1;
    //                 $a[$key2]['fieldtype']=$zd;
    //                 $a[$key2]['filepath']=$value2['file'];
    //                 $info=M('attachment')->field('filesize')->where(array('filepath'=>$value2['file']))->find();
    //                 if($info)
    //                 {
    //                     $a[$key2]['filesize']=$info['filesize'];
    //                 }
    //                 else
    //                 {
    //                     $a[$key2]['filesize']=0;
    //                 }
                    
    //             }
    //             array_push($arr,$a);
    //         }
 
    //     }
 
    //     echo $i;
    //     $j=0;
    //     foreach ($arr as $key3 => $value3) {
    //         foreach ($value3 as $key4 => $value4) {
    //            // dump($value4);
    //              $aa=M('attachment')->add($value4);
    //              if($aa>0)
    //              {
    //                  $j++;
    //              }
    //         }
    //     }
    //     echo $j;

    // }
    // public function allwenjian()
    // {
    //     $biao='zhuanye';
    //     $zd='bannerimg';
    //     $is=false;
    //     $moduleid=14;


    //     $imagearr = explode(',', 'jpg,gif,png,jpeg,bmp,ttf,tif'); 
    //     $list=M($biao)->field('id,title,userid,'.$zd)->select();
    //     $arr=array();
    //     foreach ($list as $key => $value) {
    //         if($value[$zd])
    //         {
    //             $a=array();
    //             $a['catid']=0;
    //             $a['id']=$value['id'];
    //             $a['moduleid']= $moduleid;
    //             $a['fileext']=fileext($value[$zd]);
    //             $a['isimage'] = in_array(fileext($value[$zd]),$imagearr) ? 1 : 0;
    //             if($is)
    //             {
    //                 $a['filename']=$value['title'].'.'.fileext($value[$zd]);
    //             }
    //             else
    //             {
    //                 $a['filename']=findnameorext($value[$zd],0).'.'.fileext($value[$zd]);
    //             }
    //             $a['userid']=$value['userid'];
    //             $a['isthumb']=0;
    //             $a['createtime']=time();
    //             $a['uploadip']='0.0.0.0';
    //             $a['status']=1;
    //             $a['fieldtype']=$zd;
    //             $a['filepath']=$value[$zd];
    //             $info=M('attachment')->field('filesize')->where(array('filepath'=>$value[$zd]))->find();
    //             if($info)
    //             {
    //                 $a['filesize']=$info['filesize'];
    //             }
    //             else
    //             {
    //                 $a['filesize']=0;
    //             }
    //             array_push($arr,$a);
    //         }
    //     }
    //     //dump($arr);
    //     echo count($arr);
    //     $j=0;
    //     foreach ($arr as $key3 => $value3) {
           
    //            // dump($value4);
    //              $aa=M('attachment_copy')->add($value3);
    //              if($aa>0)
    //              {
    //                  $j++;
    //              }
            
    //     }
    //     echo $j;
    // }
//资源使用统计返回数据
    public function zy_data(){
        if(IS_AJAX){
            $where = array();
            if($_POST['zyid'] && $_POST['zyid'] != -1){
                $where['zyid'] = $_POST['zyid'];
            }
            if($_POST['gwid'] && $_POST['gwid'] != -1){
                $where['gwid'] = $_POST['gwid'];
            }
            if($_POST['starttime'] != '' || $_POST['endtime'] != ''){
                $start_time = strtotime($_POST['starttime']);
                $end_time = strtotime($_POST['endtime']);
                $where['time'] = array('between',array($start_time,$end_time));
            }
            $res = $this->zy_data_deal($where);
            echo json_encode($res);
        }
    }
    //资源使用导出
    public function zy_export(){
        import("@.ORG.Excel");
        $where = array();
        if($_GET['zyid'] && $_GET['zyid'] != -1){
            $where['zyid'] = $_GET['zyid'];
        }
        if($_GET['gwid'] && $_GET['gwid'] != -1){
            $where['gwid'] = $_GET['gwid'];
        }
        if($_GET['starttime'] != '' || $_GET['endtime'] != ''){
            $start_time = strtotime($_GET['starttime']);
            $end_time = strtotime($_GET['endtime']);
            $where['time'] = array('between',array($start_time,$end_time));
        }
        $data = $this->zy_data_deal($where);
        $title = array('zy'=>array('col'=>'A','name'=>'专业'),'gw'=>array('col'=>'B','name'=>'岗位'),'xm'=>array('col'=>'C','name'=>'项目'),'file'=>array('col'=>'D','name'=>'资源名'),'num'=>array('col'=>'E','name'=>'查看次数'));
        $excel = new Excel(array('filename'=>'资源使用统计','title'=>$title,'data'=>$data,'msg'=>'数据为空'));
        $excel->Export();
    }
    //用户使用统计返回数据
    public function user_data(){
        if(IS_AJAX){
            $where = array();
            if($_POST['type'] && $_POST['type'] != -1){
                $where['type'] = $_POST['type'];
            }
            if($_POST['bjid'] && $_POST['bjid'] != -1){
                $where['bjid'] = $_POST['bjid'];
            }
            if($_POST['starttime'] != '' || $_POST['endtime'] != ''){
                $start_time = strtotime($_POST['starttime']);
                $end_time = strtotime($_POST['endtime']);
                $where['time'] = array('between',array($start_time,$end_time));
            }
            // print_r($where);die;
            $res = $this->user_data_deal($where);
            echo json_encode($res);
        }
    }
    //用户统计导出
    public function user_export(){
        import("@.ORG.Excel"); 
        $where = array();
        if($_GET['type'] && $_GET['type'] != -1){
            $where['type'] = $_GET['type'];
        }
        if($_GET['bjid'] && $_GET['bjid'] != -1){
            $where['bjid'] = $_GET['bjid'];
        }
        if($_GET['starttime'] != '' || $_GET['endtime'] != ''){
            $start_time = strtotime($_GET['starttime']);
            $end_time = strtotime($_GET['endtime']);
            $where['time'] = array('between',array($start_time,$end_time));
        }
        $data = $this->user_data_deal($where);
        $title = array('realname'=>array('col'=>'A','name'=>'姓名'),'type'=>array('col'=>'B','name'=>'身份'),'class_name'=>array('col'=>'C','name'=>'班级'),'number'=>array('col'=>'D','name'=>'学号'),'count'=>array('col'=>'E','name'=>'查看次数'));
        $excel = new Excel(array('filename'=>'用户使用统计','title'=>$title,'data'=>$data,'msg'=>'数据为空'));
        $excel->Export();
    }
    //资源数据处理
    public function zy_data_deal($where){
        // print_r($where);die;
        $data = M('zytj')->where($where)->select();
        return $data;
    }
    //用户数据处理
    public function user_data_deal($where){
        $data = M('zytj_user')->where($where)->select();
        foreach($data as $k=>$v){
            $data[$k] = $this->lg_user_data($v['userid']);
            $data[$k]['type'] = array("0"=>"老师","1"=>"学生")[$v["type"]];
            $data[$k]['count'] = M('zytj_user')->where(array("userid"=>$v['userid']))->count();
        }
        $data = $this->array_unique_new($data);
        return $data;
    }
    //查看详情
    public function see_data_details(){
        if(IS_AJAX){
            switch($_POST['cate']){
                case "1"://资源统计
                $res = M("zytj_user")->where(array("zytjid"=>$_POST['id']))->select();
                foreach($res as $k=>$v){
                    $user = $this->lg_user_data($v['userid']);
                    $res[$k]['time'] = date("Y/m/d H:i:s",$v['time']);
                    $res[$k]['class_name'] = $user['class_name'];
                    $res[$k]['number'] = $user['number'];
                    $res[$k]['realname'] = $user['realname'];
                    $res[$k]['type'] = array("0"=>"老师","1"=>"学生")[$v["type"]];
                }
                break;
                case "2"://用户统计
                $res = M('zytj_user')->where(array("userid"=>$_POST['id']))->select();
                foreach($res as $k=>$v){
                    $zytj = M('zytj')->where(array("id"=>$v['zytjid']))->find();
                    $res[$k]['time'] = date("Y/m/d H:i:s",$v['time']);
                    $res[$k]['zy'] = $zytj['zy'];
                    $res[$k]['gw'] = $zytj['gw'];
                    $res[$k]['xm'] = $zytj['xm'];
                    $res[$k]['file'] = $zytj['file'];
                }
                break;
            }
            echo json_encode($res);
        }
    }
    //处理班级数据
    public function class_data($bjid){
        $sql = "SELECT * FROM XueXiao_BanJi;";
        $class = $this->connect_sqlserver($sql);
        $class_name = "";
        foreach($class as $k=>$v){
            if($bjid == $v[0]){
                $class_name = $v[1];
            }
        }
        return $class_name;
    }
    //处理用户信息
    public function lg_user_data($userid){
        $lg_user = M('lg_user')->select();
        $user = array();
        foreach($lg_user as $k=>$v){
            if($userid == $v['userid']){
                $user['user_id'] = $v['userid'];
                if($v['number'] == null){
                    $user['number'] = '';
                }else{
                    $user['number'] = $v['number'];
                }
                $user['realname'] = $v['realname'];
                $user['class_name'] = $this->class_data($v['bjid']);
            }
        }
        
        return $user;
    }
    //去除掉相同数据
    function array_unique_new($arr){
        foreach($arr as $k=>$v){
            foreach($arr as $ke=>$ve){
                if($v['userid'] == $ve['userid'] && $k != $ke){
                    unset($arr[$k]);
                }
            }
        }
        $arr = array_values($arr);
        return $arr;
    }

}
?>